﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 委托
{
    public delegate string MymethodDelegate(int myInt);


    class Program
    {
        public delegate void Feedback(int num);
        static void Main(string[] args)
        {
            Program p = new Program();

            ///多播委托
            //Feedback feedback1 = new Feedback(p.InstanceMethod);
            //Feedback feedback2 = new Feedback(StaticMethod);

            //feedback1(2);

            //feedback2(2);
            //Console.Read();
            ///泛型委托
     
            /// 匿名委托
            Func<int, int> ann = delegate(int i)
            {
                i = i + 1;
                return i;
            };
            Action<int> ann2=delegate(int i)
            {
                i = i + 1;
        
            };


            Func<int, int, int> test = (i, j) => { i = i + 1;
                                                     i = i*j;
                                                     return i;
            };
            //Console.Write(ann(1));
            //Console.Write(ann2);
            //Console.ReadLine();
            Console.WriteLine(test(1, 2));
            Console.ReadLine();
        }

        public void InstanceMethod(int a)
        {
            Console.WriteLine(a.ToString());
        }

        public static void StaticMethod(int b)
        {
            Console.WriteLine(b * b);
        }



        /// <summary>
        /// 实例方法
        /// </summary>
        /// <param name="myInt"></param>
        /// <returns></returns>
        public string myStringMethod(int myInt)
        {
            if (myInt > 0)
                return "11111";
            if (myInt < 0)
                return "22222";
            return "3333333";
        }

        public static string mySignMethod(int myInt)
        {
            if (myInt > 0)
                return "+";
            if (myInt < 0)
                return "-";
            return "";
        }
    }
}
